package com.dengqi.mymodule.activity.fragment.fragment;


import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.dengqi.mymodule.R;
import com.dengqi.mymodule.activity.fragment.recycleview.QRecycleView;
import com.dengqi.mymodule.activity.fragment.recycleview.QRecycledapter;
import com.dengqi.mymodule.fragment.BaseFragment;
import com.module.retrofit.utils.ToastUtil;

import java.util.ArrayList;
import java.util.List;

import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;

/**
 * Author: deng
 * Date: 2020/11/19
 * Description:
 */
public class RecycleFragment extends BaseFragment {

    private QRecycleView<String> mRecycleView;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_q_recycle, container, false);
        mRecycleView = view.findViewById(R.id.recyclerView);
        mRecycleView.setRecycleAdapter(new QRecycledapter<String>() {
            @Override
            public int getLayoutResId() {
                return R.layout.item_list_string;
            }

            @Override
            public void bindData(String object, View itemView, int position) {
                TextView textView = itemView.findViewById(R.id.textView);
                textView.setText(object);
            }
        });
        mRecycleView.setAdapterClickListener(new QRecycledapter.OnItemClickListener<String>() {
            @Override
            public void onItemClick(String object, View view, int position) {
                ToastUtil.showToast(object);
            }
        });
        return view;
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        List<String> data = new ArrayList<>();
        for (int i = 0; i < 30; i++) {
            data.add("item"+i);
        }
        mRecycleView.setAdapterData(data);
    }

    public static Fragment newInstance() {
        RecycleFragment fragment = new RecycleFragment();
        return fragment;
    }
}
